#include "ActionHistoryPanel.hpp"

ActionHistoryPanel::ActionHistoryPanel():Panel(0,115, 200, 120, Panel::Static){

    title.setPosition(5, 3);
    title.setString(10, sf::Color::White, sf::Text::Underlined, std::string("History(0)"));
    add(&title);

    historyText = new Label*[10];
    for(int i = 0; i < 7; i++){
        historyText[i] = new Label(5, 20 + 13*i, 10, sf::Color::White, "");
        add(historyText[i]);
    }
}

/** 
* Regenerates history list. Call when history has changed.
*/
void ActionHistoryPanel::updateHistory(){
    title.setString("History(" + StringHelper::itos(actionHistory->size()) + ")");
    for(unsigned int i = 0; i < 7; i++){
        if(actionHistory->size() > i && !actionHistory->empty())
            historyText[i]->setString("(" + StringHelper::itos(actionHistory->size() - i) + ")" + actionHistory->at(i)->description());
        else
            historyText[i]->setString("");
    }
}

/** 
* Set the source of the history list, and update ui.
*/
void ActionHistoryPanel::updateHistory(deque<BaseAction*>* history){
    actionHistory = history;
    updateHistory();
}